﻿@model PagingDataSet<Comment>
@{
    var commentedObjectId = ViewData.Get<long>("commentedObjectId", 0);
    var commentCount = ViewData.Get<int>("commentCount", 0);
    var disapprovedCount = ViewData.Get<int>("disapprovedCount", 0);

    var isOnlyAuthor = ViewData.Get<bool>("isOnlyAuthor", false);
    var pageIndex = ViewData.Get("pageIndex", 1);
    int floor = (pageIndex - 1) * 10 + 1;
    var _currentUser = UserContext.CurrentUser;
}
@if (Model != null && Model.TotalRecords > 0)
{
    foreach (var comment in Model)
    {
    <div class="media">
        <div class="media-left">
            @Html.ShowUserAvatar(userId: comment.UserId, avatarSizeType: AvatarSizeType.Small)
        </div>
        <div class="media-body commentContent" data-id="@comment.Id">
            <h4 class="media-heading"><a href="@SiteUrls.Instance().MyHome(comment.UserId)">@comment.Author</a><small class="pull-right">#@floor</small></h4>
            <p>@Html.Raw(comment.Body)</p>
            <div class="tn-feedback ">
                <small class="pull-left text-muted">@comment.DateCreated.ToFriendlyDate()</small>
                <ul id="operation" class="list-inline text-right text-muted" onmouseover="$.fn.showoperation(this);" onmouseout="$.fn.hideoperation(this);">
                    @if (_currentUser != null)
                    {
                        if (_currentUser.UserId == comment.UserId)
                        {
                        <li><a href="javascript:;" class="delete" name="deletecomment" data-id="@comment.Id" style="display:none"><i class="fa fa-trash"></i> 删除</a></li>
                        }

                        <li><a href="javascript:;" class="reply" data-href="@CachedUrlHelper.Action("_Comment", "Post", null, new RouteValueDictionary { { "parentId", comment.Id }, { "commentedObjectId", commentedObjectId } })" data-isshow="0"><i class="fa fa-reply"></i> 回复</a></li>
                    }
                    else
                    {
                    <li></li>
                    }
                </ul>
                <div class="_ChildrenComment" style="margin-top:10px">
                    @Html.Action("_ChildrenComment", "Post", new { parentId = comment.Id, commentedObjectId = commentedObjectId })
                </div>
            </div>
        </div>

    </div>
        floor++;
    }
    <div class="text-center">
        @Html.AjaxPagingButton(Model, "_ListComment", CachedUrlHelper.Action("_ListComment", "Post", null, new RouteValueDictionary { { "threadId", commentedObjectId }, { "isOnlyAuthor", isOnlyAuthor } }))
    </div>
}
else
{
    <div class="media">
        <div class="media-body">
            <h4 class="media-heading text-warning text-center">暂无评论</h4>
        </div>
    </div>
}


<script type="text/javascript">
    require(['jquery', 'tnlayer','page'], function ($, tnlayer) {
        $(function myfunction() {
            var TotalRecords = @Model.TotalRecords;
            var AuditCount =   parseInt(@commentCount)-parseInt( TotalRecords);
            $("#AuditCount").html("审核中("+AuditCount+")");

        })
        //悬停显示删除
        $.fn.showoperation=function(e) {
            var commentdel = $(e).find("a");
            if (commentdel.length > 1) {
                commentdel[0].style.display = "inline";
            }
        }
        $.fn.hideoperation=function(e) {
            var commentdel = $(e).find("a");
            if (commentdel.length > 1) {
                commentdel[0].style.display = "none";
            }
        }
        //删除
        $('.delete').on("click", function () {
            var $this=$(this);
            layer.confirm("是否删除", { btn: ['确认', '取消'] }, function () {
                $.post("@CachedUrlHelper.Action("DeleteComment", "Post")", { commentId:$this.data('id')}, function (data) {
                    if (data.state) {
                        layer.msg("删除成功", {
                            icon: 1
                        })
                        $.get("@CachedUrlHelper.Action("_ListComment", "Post")",{ threadId:@commentedObjectId},function(data){
                            $('#_ListComment').html(data);
                        });
                    }
                });
            })
        })})
</script>
